package com.normal.utils.sp

import android.os.Parcelable
import com.tencent.mmkv.MMKV

/**
 *基础mmkv类
 * 委托处理
 *@author jiang create by 2022/11/9 20 07
 */
open class SpData(name: String) {
    val mmkv: MMKV = MMKV.mmkvWithID(name)
    protected fun boolean(key: String, defValue: Boolean = false) = BooleanProperty(key, defValue)
    protected fun int(key: String, defValue: Int = 0) = IntProperty(key, defValue)
    protected fun float(key: String, defValue: Float = 0f) = FloatProperty(key, defValue)
    protected fun long(key: String, defValue: Long = 0L) = LongProperty(key, defValue)
    protected fun double(key: String, defValue: Double = 0.0) = DoubleProperty(key, defValue)
    protected fun string(key: String, defValue: String = "") = StringProperty(key, defValue)
    protected fun array(key: String, defValue: ByteArray = ByteArray(0)) =
        ByteArrayProperty(key, defValue)

    protected fun stringSet(key: String, defValue: Set<String>? = null) =
        SringSetProperty(key, defValue)

    protected fun <T : Parcelable> obj(key: String, def: T) = ParcelableProperty(key, def)

    fun removeKey(key: Array<String>) {
        mmkv.removeValuesForKeys(key)
    }

    fun removeKey(key: String) {
        mmkv.removeValueForKey(key)
    }

}